package com.panshi.config;

import com.baomidou.mybatisplus.core.injector.ISqlInjector;
import com.baomidou.mybatisplus.extension.injector.LogicSqlInjector;
import com.baomidou.mybatisplus.extension.plugins.OptimisticLockerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;

@MapperScan("com.panshi.mapper")
//默认开启的
@EnableTransactionManagement
@Configuration
public class MyBatisPlusConfig {


    //注册乐观锁插件
    @Bean
    public OptimisticLockerInterceptor optimisticLockerInterceptor() {
        return new OptimisticLockerInterceptor();
    }

    //分页插件
    @Bean
    public PaginationInterceptor paginationInterceptor() {
         return new PaginationInterceptor();
    }

    //逻辑删除组件            3.3.0后不需要配置
    @Bean
    public ISqlInjector sqlInjector(){
        return new LogicSqlInjector();
    }

    /**
     * sql执行效率插件
     */
    //@Bean
    //@Profile({"dev","text"})    //设置dev text 环境开启
    //public PerformanceInterceptor performanceInterceptor(){
    //    PerformanceInterceptor pi = new PerformanceInterceptor();
    //    //在工作中 ，不允许用户等待
    //    pi.setMaxTime(100);//设置SQL执行最大时间 超过不执行
    //    pi.setFormat(true); //开启格式化支持
    //    return pi;
    //}
}
